# coding=utf-8

def bag(m, n, series=list()):
    if n == 1:
        for i in range(m+1):
            print(series+[i])
    else:
        for i in range(m+1):
            bag(m-i, n-1, series+[i])

def index(lists, reposen):
    if len(lists) == 1:
        table = lists[0]
        ddd = reposen[table]
        return ddd
    else:
        for i in lists:
            if len(i) == 1:
                reposen = reposen[int(i)]
            else:
                reposen = reposen[i]
            lists.remove(i)
            return index(lists, reposen)

def data_var(variable, data, list_dict):
    if len(variable) == 1:
        i = variable[0]
        index_data = list_dict[i]
        data = data.replace(i, index_data)
        return data
    else:
        for i in variable:
            index_data = list_dict[i]
            data= data.replace(i, index_data)
            variable.remove(i)
            return data_var(variable, data, list_dict)


if __name__ == '__main__':
    # a = 'data.0.id'
    # aa = a.split('.')
    # reposen = {"data": [{"id": 123}, {'ids":222'}]}
    # # b = reposen['data']
    # # c = b[0]
    # # d = c['id']
    # # print(b,c,d)
    # abc = index(aa, reposen)
    # print(abc)
    list_dict = {"$id":"123456", "$po":"2345"}
    data = '{"typeCode":"pytestcode","typeName":"pytest主分类code","id":$id,"parentId":$po,"typeLevel":1}'
    var = ['$id', '$po']
    c = data_var(var, data, list_dict)
    print(c)